home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLSR106.ARJ / GETENV.C < prev    next >
C/C++ Source or Header  |  1992-03-02  |  2KB  |  73 lines

  1. /* This file may have been modified by DJ Delorie (Jan 1991).  If so,
  2. ** these modifications are Coyright (C) 1991 DJ Delorie, 24 Kirsten Ave,
  3. ** Rochester NH, 03867-2954, USA.
  4. */
  5.  
  6. /*
  7.  * Copyright (c) 1987 Regents of the University of California.
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms are permitted
  11.  * provided that: (1) source distributions retain this entire copyright
  12.  * notice and comment, and (2) distributions including binaries display
  13.  * the following acknowledgement:  ``This product includes software
  14.  * developed by the University of California, Berkeley and its contributors''
  15.  * in the documentation or other materials provided with the distribution
  16.  * and in all advertising materials mentioning features or use of this
  17.  * software. Neither the name of the University nor the names of its
  18.  * contributors may be used to endorse or promote products derived
  19.  * from this software without specific prior written permission.
  20.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  21.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  22.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  23.  */
  24.  
  25. #if defined(LIBC_SCCS) && !defined(lint)
  26. static char sccsid[] = "@(#)getenv.c    5.7 (Berkeley) 6/1/90";
  27. #endif /* LIBC_SCCS and not lint */
  28.  
  29. #include <stdlib.h>
  30. #include <stddef.h>
  31.  
  32. /*
  33.  * getenv --
  34.  *    Returns ptr to value associated with name, if any, else NULL.
  35.  */
  36. char *
  37. getenv(name)
  38.     const char *name;
  39. {
  40.     int offset;
  41.     char *_findenv();
  42.  
  43.     return(_findenv(name, &offset));
  44. }
  45.  
  46. /*
  47.  * _findenv --
  48.  *    Returns pointer to value associated with name, if any, else NULL.
  49.  *    Sets offset to be the offset of the name/value combination in the
  50.  *    environmental array, for use by setenv(3) and unsetenv(3).
  51.  *    Explicitly removes '=' in argument name.
  52.  *
  53.  *    This routine *should* be a static; don't use it.
  54.  */
  55. char *
  56. _findenv(name, offset)
  57.     register char *name;
  58.     int *offset;
  59. {
  60.     extern char **environ;
  61.     register int len;
  62.     register char **P, *C;
  63.  
  64.     for (C = name, len = 0; *C && *C != '='; ++C, ++len);
  65.     for (P = environ; *P; ++P)
  66.         if (!strncmp(*P, name, len))
  67.             if (*(C = *P + len) == '=') {
  68.                 *offset = P - environ;
  69.                 return(++C);
  70.             }
  71.     return(NULL);
  72. }
  73.